home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Developer & Web Development Tools / Inno Setup 5.2.3 / isetup-5.2.3.exe / {app} / Examples / CodeClasses.iss < prev    next >
Text File  |  2008-03-08  |  11KB  |  321 lines

  1. ; -- CodeClasses.iss --
  2. ;
  3. ; This script shows how to use the WizardForm object and the various VCL classes.
  4.  
  5. [Setup]
  6. AppName=My Program
  7. AppVerName=My Program version 1.5
  8. CreateAppDir=no
  9. DisableProgramGroupPage=yes
  10. DefaultGroupName=My Program
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. WindowVisible=yes
  13. OutputDir=userdocs:Inno Setup Examples Output
  14.  
  15. [Files]
  16. Source: compiler:WizModernSmallImage.bmp; Flags: dontcopy
  17.  
  18. [Code]
  19. procedure ButtonOnClick(Sender: TObject);
  20. begin
  21.   MsgBox('You clicked the button!', mbInformation, mb_Ok);
  22. end;
  23.  
  24. procedure FormButtonOnClick(Sender: TObject);
  25. var
  26.   Form: TSetupForm;
  27.   OKButton, CancelButton: TNewButton;
  28. begin
  29.   Form := CreateCustomForm();
  30.   try
  31.     Form.ClientWidth := ScaleX(256);
  32.     Form.ClientHeight := ScaleY(256);
  33.     Form.Caption := 'TSetupForm';
  34.     Form.CenterInsideControl(WizardForm, False);
  35.  
  36.     OKButton := TNewButton.Create(Form);
  37.     OKButton.Parent := Form;
  38.     OKButton.Width := ScaleX(75);
  39.     OKButton.Height := ScaleY(23);
  40.     OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 10);
  41.     OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  42.     OKButton.Caption := 'OK';
  43.     OKButton.ModalResult := mrOk;
  44.  
  45.     CancelButton := TNewButton.Create(Form);
  46.     CancelButton.Parent := Form;
  47.     CancelButton.Width := ScaleX(75);
  48.     CancelButton.Height := ScaleY(23);
  49.     CancelButton.Left := Form.ClientWidth - ScaleX(75 + 10);
  50.     CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
  51.     CancelButton.Caption := 'Cancel';
  52.     CancelButton.ModalResult := mrCancel;
  53.     CancelButton.Cancel := True;
  54.  
  55.     Form.ActiveControl := OKButton;
  56.  
  57.     if Form.ShowModal() = mrOk then
  58.       MsgBox('You clicked OK.', mbInformation, MB_OK);
  59.   finally
  60.     Form.Free();
  61.   end;
  62. end;
  63.  
  64. procedure CreateTheWizardPages;
  65. var
  66.   Page: TWizardPage;
  67.   Button, FormButton: TNewButton;
  68.   CheckBox: TNewCheckBox;
  69.   Edit: TNewEdit;
  70.   PasswordEdit: TPasswordEdit;
  71.   Memo: TNewMemo;
  72.   ComboBox: TNewComboBox;
  73.   ListBox: TNewListBox;
  74.   StaticText, ProgressBarLabel: TNewStaticText;
  75.   ProgressBar: TNewProgressBar;
  76.   CheckListBox, CheckListBox2: TNewCheckListBox;
  77.   FolderTreeView: TFolderTreeView;
  78.   BitmapImage, BitmapImage2, BitmapImage3: TBitmapImage;
  79.   BitmapFileName: String;
  80.   RichEditViewer: TRichEditViewer;
  81. begin
  82.   { TButton and others }
  83.  
  84.   Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'TButton and others');
  85.  
  86.   Button := TNewButton.Create(Page);
  87.   Button.Width := ScaleX(75);
  88.   Button.Height := ScaleY(23);
  89.   Button.Caption := 'TNewButton';
  90.   Button.OnClick := @ButtonOnClick;
  91.   Button.Parent := Page.Surface;
  92.  
  93.   CheckBox := TNewCheckBox.Create(Page);
  94.   CheckBox.Top := Button.Top + Button.Height + ScaleY(8);
  95.   CheckBox.Width := Page.SurfaceWidth;
  96.   CheckBox.Height := ScaleY(17);
  97.   CheckBox.Caption := 'TNewCheckBox';
  98.   CheckBox.Checked := True;
  99.   CheckBox.Parent := Page.Surface;
  100.  
  101.   Edit := TNewEdit.Create(Page);
  102.   Edit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  103.   Edit.Width := Page.SurfaceWidth div 2 - ScaleX(8);
  104.   Edit.Text := 'TNewEdit';
  105.   Edit.Parent := Page.Surface;
  106.  
  107.   PasswordEdit := TPasswordEdit.Create(Page);
  108.   PasswordEdit.Left := Page.SurfaceWidth - Edit.Width;
  109.   PasswordEdit.Top := CheckBox.Top + CheckBox.Height + ScaleY(8);
  110.   PasswordEdit.Width := Edit.Width;
  111.   PasswordEdit.Text := 'TPasswordEdit';
  112.   PasswordEdit.Parent := Page.Surface;
  113.  
  114.   Memo := TNewMemo.Create(Page);
  115.   Memo.Top := Edit.Top + Edit.Height + ScaleY(8);
  116.   Memo.Width := Page.SurfaceWidth;
  117.   Memo.Height := ScaleY(89);
  118.   Memo.ScrollBars := ssVertical;
  119.   Memo.Text := 'TNewMemo';
  120.   Memo.Parent := Page.Surface;
  121.  
  122.   FormButton := TNewButton.Create(Page);
  123.   FormButton.Top := Memo.Top + Memo.Height + ScaleY(8);
  124.   FormButton.Width := ScaleX(75);
  125.   FormButton.Height := ScaleY(23);
  126.   FormButton.Caption := 'TSetupForm';
  127.   FormButton.OnClick := @FormButtonOnClick;
  128.   FormButton.Parent := Page.Surface;
  129.  
  130.   { TComboBox and others }
  131.  
  132.   Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TComboBox and others');
  133.  
  134.   ComboBox := TNewComboBox.Create(Page);
  135.   ComboBox.Width := Page.SurfaceWidth;
  136.   ComboBox.Parent := Page.Surface;
  137.   ComboBox.Style := csDropDownList;
  138.   ComboBox.Items.Add('TComboBox');
  139.   ComboBox.ItemIndex := 0;
  140.  
  141.   ListBox := TNewListBox.Create(Page);
  142.   ListBox.Top := ComboBox.Top + ComboBox.Height + ScaleY(8);
  143.   ListBox.Width := Page.SurfaceWidth;
  144.   ListBox.Height := ScaleY(97);
  145.   ListBox.Parent := Page.Surface;
  146.   ListBox.Items.Add('TListBox');
  147.   ListBox.ItemIndex := 0;
  148.  
  149.   StaticText := TNewStaticText.Create(Page);
  150.   StaticText.Top := ListBox.Top + ListBox.Height + ScaleY(8);
  151.   StaticText.Caption := 'TNewStaticText';
  152.   StaticText.AutoSize := True;
  153.   StaticText.Parent := Page.Surface;
  154.  
  155.   ProgressBarLabel := TNewStaticText.Create(Page);
  156.   ProgressBarLabel.Top := StaticText.Top + StaticText.Height + ScaleY(8);
  157.   ProgressBarLabel.Caption := 'TNewProgressBar';
  158.   ProgressBarLabel.AutoSize := True;
  159.   ProgressBarLabel.Parent := Page.Surface;
  160.  
  161.   ProgressBar := TNewProgressBar.Create(Page);
  162.   ProgressBar.Left := ProgressBarLabel.Width + ScaleX(8);
  163.   ProgressBar.Top := ProgressBarLabel.Top;
  164.   ProgressBar.Width := Page.SurfaceWidth - ProgressBar.Left;
  165.   ProgressBar.Height := ProgressBarLabel.Height + ScaleY(8);
  166.   ProgressBar.Parent := Page.Surface;
  167.   ProgressBar.Position := 25;
  168.  
  169.   { TNewCheckListBox }
  170.  
  171.   Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TNewCheckListBox');
  172.  
  173.   CheckListBox := TNewCheckListBox.Create(Page);
  174.   CheckListBox.Width := Page.SurfaceWidth;
  175.   CheckListBox.Height := ScaleY(97);
  176.   CheckListBox.Flat := True;
  177.   CheckListBox.Parent := Page.Surface;
  178.   CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  179.   CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, True, True, nil);
  180.   CheckListBox.AddRadioButton('TNewCheckListBox', '', 1, False, True, nil);
  181.   CheckListBox.AddCheckBox('TNewCheckListBox', '', 0, True, True, False, True, nil);
  182.  
  183.   CheckListBox2 := TNewCheckListBox.Create(Page);
  184.   CheckListBox2.Top := CheckListBox.Top + CheckListBox.Height + ScaleY(8);
  185.   CheckListBox2.Width := Page.SurfaceWidth;
  186.   CheckListBox2.Height := ScaleY(97);
  187.   CheckListBox2.BorderStyle := bsNone;
  188.   CheckListBox2.ParentColor := True;
  189.   CheckListBox2.MinItemHeight := WizardForm.TasksList.MinItemHeight;
  190.   CheckListBox2.ShowLines := False;
  191.   CheckListBox2.WantTabs := True;
  192.   CheckListBox2.Parent := Page.Surface;
  193.   CheckListBox2.AddGroup('TNewCheckListBox', '', 0, nil);
  194.   CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, True, True, nil);
  195.   CheckListBox2.AddRadioButton('TNewCheckListBox', '', 0, False, True, nil);
  196.  
  197.   { TFolderTreeView }
  198.  
  199.   Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TFolderTreeView');
  200.  
  201.   FolderTreeView := TFolderTreeView.Create(Page);
  202.   FolderTreeView.Width := Page.SurfaceWidth;
  203.   FolderTreeView.Height := Page.SurfaceHeight;
  204.   FolderTreeView.Parent := Page.Surface;
  205.   FolderTreeView.Directory := ExpandConstant('{src}');
  206.  
  207.   { TBitmapImage }
  208.  
  209.   Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TBitmapImage');
  210.  
  211.   BitmapFileName := ExpandConstant('{tmp}\WizModernSmallImage.bmp');
  212.   ExtractTemporaryFile(ExtractFileName(BitmapFileName));
  213.  
  214.   BitmapImage := TBitmapImage.Create(Page);
  215.   BitmapImage.AutoSize := True;
  216.   BitmapImage.Bitmap.LoadFromFile(BitmapFileName);
  217.   BitmapImage.Parent := Page.Surface;
  218.  
  219.   BitmapImage2 := TBitmapImage.Create(Page);
  220.   BitmapImage2.BackColor := $400000;
  221.   BitmapImage2.Bitmap := BitmapImage.Bitmap;
  222.   BitmapImage2.Center := True;
  223.   BitmapImage2.Left := BitmapImage.Width + 10;
  224.   BitmapImage2.Height := 2*BitmapImage.Height;
  225.   BitmapImage2.Width := 2*BitmapImage.Width;
  226.   BitmapImage2.Parent := Page.Surface;
  227.  
  228.   BitmapImage3 := TBitmapImage.Create(Page);
  229.   BitmapImage3.Bitmap := BitmapImage.Bitmap;
  230.   BitmapImage3.Stretch := True;
  231.   BitmapImage3.Left := 3*BitmapImage.Width + 20;
  232.   BitmapImage3.Height := 4*BitmapImage.Height;
  233.   BitmapImage3.Width := 4*BitmapImage.Width;
  234.   BitmapImage3.Parent := Page.Surface;
  235.  
  236.   { TRichViewer }
  237.  
  238.   Page := CreateCustomPage(Page.ID, 'Custom wizard page controls', 'TRichViewer');
  239.  
  240.   RichEditViewer := TRichEditViewer.Create(Page);
  241.   RichEditViewer.Width := Page.SurfaceWidth;
  242.   RichEditViewer.Height := Page.SurfaceHeight;
  243.   RichEditViewer.Parent := Page.Surface;
  244.   RichEditViewer.ScrollBars := ssVertical;
  245.   RichEditViewer.UseRichEdit := True;
  246.   RichEditViewer.RTFText := '{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue128;}\viewkind4\uc1\pard\f0\fs20 T\cf1 Rich\cf2 Edit\cf3 Viewer\cf0\par}';
  247.   RichEditViewer.ReadOnly := True;
  248. end;
  249.  
  250. procedure AboutButtonOnClick(Sender: TObject);
  251. begin
  252.   MsgBox('This demo shows some features of the various form objects and control classes.', mbInformation, mb_Ok);
  253. end;
  254.  
  255. procedure URLLabelOnClick(Sender: TObject);
  256. var
  257.   ErrorCode: Integer;
  258. begin
  259.   ShellExec('open', 'http://www.innosetup.com', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  260. end;
  261.  
  262. procedure CreateAboutButtonAndURLLabel(ParentForm: TSetupForm; CancelButton: TNewButton);
  263. var
  264.   AboutButton: TNewButton;
  265.   URLLabel: TNewStaticText;
  266. begin
  267.   AboutButton := TNewButton.Create(ParentForm);
  268.   AboutButton.Left := ParentForm.ClientWidth - CancelButton.Left - CancelButton.Width;
  269.   AboutButton.Top := CancelButton.Top;
  270.   AboutButton.Width := CancelButton.Width;
  271.   AboutButton.Height := CancelButton.Height;
  272.   AboutButton.Caption := '&About...';
  273.   AboutButton.OnClick := @AboutButtonOnClick;
  274.   AboutButton.Parent := ParentForm;
  275.  
  276.   URLLabel := TNewStaticText.Create(ParentForm);
  277.   URLLabel.Caption := 'www.innosetup.com';
  278.   URLLabel.Cursor := crHand;
  279.   URLLabel.OnClick := @URLLabelOnClick;
  280.   URLLabel.Parent := ParentForm;
  281.   { Alter Font *after* setting Parent so the correct defaults are inherited first }
  282.   URLLabel.Font.Style := URLLabel.Font.Style + [fsUnderline];
  283.   URLLabel.Font.Color := clBlue;
  284.   URLLabel.Top := AboutButton.Top + AboutButton.Height - URLLabel.Height - 2;
  285.   URLLabel.Left := AboutButton.Left + AboutButton.Width + ScaleX(20);
  286. end;
  287.  
  288. procedure InitializeWizard();
  289. var
  290.   BackgroundBitmapImage: TBitmapImage;
  291.   BackgroundBitmapText: TNewStaticText;
  292. begin
  293.   { Custom wizard pages }
  294.  
  295.   CreateTheWizardPages;
  296.   
  297.   { Custom controls }
  298.  
  299.   CreateAboutButtonAndURLLabel(WizardForm, WizardForm.CancelButton);
  300.  
  301.   BackgroundBitmapImage := TBitmapImage.Create(MainForm);
  302.   BackgroundBitmapImage.Left := 50;
  303.   BackgroundBitmapImage.Top := 90;
  304.   BackgroundBitmapImage.AutoSize := True;
  305.   BackgroundBitmapImage.Bitmap := WizardForm.WizardBitmapImage.Bitmap;
  306.   BackgroundBitmapImage.Parent := MainForm;
  307.   
  308.   BackgroundBitmapText := TNewStaticText.Create(MainForm);
  309.   BackgroundBitmapText.Left := BackgroundBitmapImage.Left;
  310.   BackgroundBitmapText.Top := BackgroundBitmapImage.Top + BackgroundBitmapImage.Height + ScaleY(8);
  311.   BackgroundBitmapText.Caption := 'TBitmapImage';
  312.   BackgroundBitmapText.Parent := MainForm;
  313. end;
  314.  
  315. procedure InitializeUninstallProgressForm();
  316. begin
  317.   { Custom controls }
  318.  
  319.   CreateAboutButtonAndURLLabel(UninstallProgressForm, UninstallProgressForm.CancelButton);
  320. end;
  321.